<?php


namespace app\api\controller;
use think\Controller;
use app\api\model\Login as LoginModel;
use think\facade\Cache;
class Login extends Controller
{
    public function test($token=""){
        if($token=="111"){
            session('username',$username);
            json(200,'正常');
        }else{
            json(-1,'请先登录',);
        }

    }

    public function doLogin($username,$password){

        //2.数据库获取
        $user=LoginModel::where('username',$username)->find();
        //3.返回
        if(empty($user)) {
            json(-1,'用户不存在');
        }
        if($user['password'] == $password){
            $token=md5('cb'.'cypt'.time());
            Cache::set('token',$token,3600);
            session('token',$token);
            json(200,'登录成功',$token);
        }
        else{
            $this->error('用户或密码不正确');
        }
    }
}